#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int N = 1000010;
long long row_sum[N], col_sum[N];
int n = 0, m = 0;

int main() {
    scanf("%d%d", &n, &m);
    int x = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &x);
            row_sum[i] += x;
            col_sum[j] += x;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            long long y = row_sum[i] + col_sum[j];
            printf("%lld ", y);
        }
        printf("\n");
    }
    return 0;
}